<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - include/caffe/util/db_leveldb.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../index.html">top level</a> - <a href="index.html">include/caffe/util</a> - db_leveldb.hpp<span style="font-size: 80%;"> (source / <a href="db_leveldb.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">31</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">18</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifdef USE_LEVELDB</a>
<span class="lineNum">       2 </span>            : #ifndef CAFFE_UTIL_DB_LEVELDB_HPP
<span class="lineNum">       3 </span>            : #define CAFFE_UTIL_DB_LEVELDB_HPP
<span class="lineNum">       4 </span>            : 
<span class="lineNum">       5 </span>            : #include &lt;string&gt;
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #include &quot;leveldb/db.h&quot;
<span class="lineNum">       8 </span>            : #include &quot;leveldb/write_batch.h&quot;
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;caffe/util/db.hpp&quot;
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : namespace caffe { namespace db {
<span class="lineNum">      13 </span>            : 
<a name="14"><span class="lineNum">      14 </span>            : class LevelDBCursor : public Cursor {</a>
<span class="lineNum">      15 </span>            :  public:
<span class="lineNum">      16 </span><span class="lineNoCov">          0 :   explicit LevelDBCursor(leveldb::Iterator* iter)</span>
<span class="lineNum">      17 </span><span class="lineNoCov">          0 :     : iter_(iter) {</span>
<span class="lineNum">      18 </span>            :     SeekToFirst();
<a name="19"><span class="lineNum">      19 </span><span class="lineNoCov">          0 :     CHECK(iter_-&gt;status().ok()) &lt;&lt; iter_-&gt;status().ToString();</span></a>
<a name="20"><span class="lineNum">      20 </span><span class="lineNoCov">          0 :   }</span></a>
<a name="21"><span class="lineNum">      21 </span><span class="lineNoCov">          0 :   ~LevelDBCursor() { delete iter_; }</span></a>
<a name="22"><span class="lineNum">      22 </span><span class="lineNoCov">          0 :   virtual void SeekToFirst() { iter_-&gt;SeekToFirst(); }</span></a>
<a name="23"><span class="lineNum">      23 </span><span class="lineNoCov">          0 :   virtual void Next() { iter_-&gt;Next(); }</span></a>
<a name="24"><span class="lineNum">      24 </span><span class="lineNoCov">          0 :   virtual string key() { return iter_-&gt;key().ToString(); }</span></a>
<span class="lineNum">      25 </span><span class="lineNoCov">          0 :   virtual string value() { return iter_-&gt;value().ToString(); }</span>
<span class="lineNum">      26 </span><span class="lineNoCov">          0 :   virtual bool valid() { return iter_-&gt;Valid(); }</span>
<span class="lineNum">      27 </span>            : 
<span class="lineNum">      28 </span>            :  private:
<span class="lineNum">      29 </span>            :   leveldb::Iterator* iter_;
<a name="30"><span class="lineNum">      30 </span>            : };</a>
<span class="lineNum">      31 </span>            : 
<a name="32"><span class="lineNum">      32 </span><span class="lineNoCov">          0 : class LevelDBTransaction : public Transaction {</span></a>
<a name="33"><span class="lineNum">      33 </span>            :  public:</a>
<span class="lineNum">      34 </span><span class="lineNoCov">          0 :   explicit LevelDBTransaction(leveldb::DB* db) : db_(db) { CHECK_NOTNULL(db_); }</span>
<span class="lineNum">      35 </span><span class="lineNoCov">          0 :   virtual void Put(const string&amp; key, const string&amp; value) {</span>
<a name="36"><span class="lineNum">      36 </span><span class="lineNoCov">          0 :     batch_.Put(key, value);</span></a>
<span class="lineNum">      37 </span><span class="lineNoCov">          0 :   }</span>
<span class="lineNum">      38 </span><span class="lineNoCov">          0 :   virtual void Commit() {</span>
<span class="lineNum">      39 </span><span class="lineNoCov">          0 :     leveldb::Status status = db_-&gt;Write(leveldb::WriteOptions(), &amp;batch_);</span>
<span class="lineNum">      40 </span><span class="lineNoCov">          0 :     CHECK(status.ok()) &lt;&lt; &quot;Failed to write batch to leveldb &quot;</span>
<span class="lineNum">      41 </span><span class="lineNoCov">          0 :                        &lt;&lt; std::endl &lt;&lt; status.ToString();</span>
<span class="lineNum">      42 </span><span class="lineNoCov">          0 :   }</span>
<span class="lineNum">      43 </span>            : 
<span class="lineNum">      44 </span>            :  private:
<span class="lineNum">      45 </span>            :   leveldb::DB* db_;
<span class="lineNum">      46 </span>            :   leveldb::WriteBatch batch_;
<span class="lineNum">      47 </span>            : 
<span class="lineNum">      48 </span>            :   DISABLE_COPY_AND_ASSIGN(LevelDBTransaction);
<span class="lineNum">      49 </span>            : };
<span class="lineNum">      50 </span>            : 
<span class="lineNum">      51 </span>            : class LevelDB : public DB {
<a name="52"><span class="lineNum">      52 </span>            :  public:</a>
<span class="lineNum">      53 </span><span class="lineNoCov">          0 :   LevelDB() : db_(NULL) { }</span>
<a name="54"><span class="lineNum">      54 </span><span class="lineNoCov">          0 :   virtual ~LevelDB() { Close(); }</span></a>
<span class="lineNum">      55 </span>            :   virtual void Open(const string&amp; source, Mode mode);
<span class="lineNum">      56 </span><span class="lineNoCov">          0 :   virtual void Close() {</span>
<span class="lineNum">      57 </span><span class="lineNoCov">          0 :     if (db_ != NULL) {</span>
<span class="lineNum">      58 </span><span class="lineNoCov">          0 :       delete db_;</span>
<span class="lineNum">      59 </span><span class="lineNoCov">          0 :       db_ = NULL;</span>
<a name="60"><span class="lineNum">      60 </span>            :     }</a>
<span class="lineNum">      61 </span><span class="lineNoCov">          0 :   }</span>
<span class="lineNum">      62 </span><span class="lineNoCov">          0 :   virtual LevelDBCursor* NewCursor() {</span>
<a name="63"><span class="lineNum">      63 </span><span class="lineNoCov">          0 :     return new LevelDBCursor(db_-&gt;NewIterator(leveldb::ReadOptions()));</span></a>
<span class="lineNum">      64 </span>            :   }
<span class="lineNum">      65 </span><span class="lineNoCov">          0 :   virtual LevelDBTransaction* NewTransaction() {</span>
<span class="lineNum">      66 </span><span class="lineNoCov">          0 :     return new LevelDBTransaction(db_);</span>
<span class="lineNum">      67 </span>            :   }
<span class="lineNum">      68 </span>            : 
<span class="lineNum">      69 </span>            :  private:
<span class="lineNum">      70 </span>            :   leveldb::DB* db_;
<span class="lineNum">      71 </span>            : };
<span class="lineNum">      72 </span>            : 
<span class="lineNum">      73 </span>            : 
<span class="lineNum">      74 </span>            : }  // namespace db
<span class="lineNum">      75 </span>            : }  // namespace caffe
<span class="lineNum">      76 </span>            : 
<span class="lineNum">      77 </span>            : #endif  // CAFFE_UTIL_DB_LEVELDB_HPP
<span class="lineNum">      78 </span>            : #endif  // USE_LEVELDB
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
